home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / decprom / RCS / fsIndex.c,v < prev    next >
Encoding:
Text File  |  1990-02-17  |  6.2 KB  |  268 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.16.16.14.13;  author shirriff;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* 
  26.  * fsIndex.c --
  27.  *
  28.  *    Routines to allow moving through a files block pointers.
  29.  *
  30.  * Copyright 1986 Regents of the University of California
  31.  * All rights reserved.
  32.  */
  33.  
  34. #ifdef notdef
  35. static char rcsid[] = "$Header: /sprite/src/boot/dsprom/RCS/fsIndex.c,v 1.1 90/02/13 23:40:33 shirriff Exp $ SPRITE (Berkeley)";
  36. #endif not lint
  37.  
  38. #include "sprite.h"
  39. #include "fsBoot.h"
  40. #include "kernel/byte.h"
  41.  
  42. char    firstBlockBuffer[FS_BLOCK_SIZE];
  43. char    secondBlockBuffer[FS_BLOCK_SIZE];
  44.  
  45.  
  46. /*
  47.  *----------------------------------------------------------------------
  48.  *
  49.  * MakePtrAccessible --
  50.  *
  51.  *    Make the block pointer in the file descriptor accessible.  This
  52.  *    may entail reading in indirect blocks and locking them down in the
  53.  *    cache.
  54.  *
  55.  * Results:
  56.  *    None.
  57.  *
  58.  * Side effects:
  59.  *    Indirect blocks are locked down in the cache.
  60.  *
  61.  *----------------------------------------------------------------------
  62.  */
  63.  
  64. static ReturnStatus
  65. MakePtrAccessible(handlePtr, indexInfoPtr, descPtr)
  66.     register    Fsio_FileIOHandle     *handlePtr;
  67.     register    BlockIndexInfo      *indexInfoPtr;
  68.     register    Fsdm_FileDescriptor *descPtr;
  69. {
  70.     register     int          *blockAddrPtr;
  71.  
  72.     /* 
  73.      * Read in the first block.
  74.      */
  75.  
  76.     if (indexInfoPtr->firstBlockNil) {
  77.     FsDeviceBlockIO(FS_READ, &fsDevice,
  78.               descPtr->indirect[indexInfoPtr->indexType],
  79.               FS_FRAGMENTS_PER_BLOCK, firstBlockBuffer);
  80.     }
  81.  
  82.     blockAddrPtr = 
  83.     (int *) (firstBlockBuffer + sizeof(int) * indexInfoPtr->firstIndex);
  84.  
  85.     if (indexInfoPtr->indexType == FS_INDIRECT) {
  86.     indexInfoPtr->blockAddrPtr = blockAddrPtr;
  87.     return(SUCCESS);
  88.     }
  89.  
  90.     /* 
  91.      * Get the second level block.
  92.      */
  93.  
  94.     FsDeviceBlockIO(FS_READ, &fsDevice, *blockAddrPtr,
  95.                FS_FRAGMENTS_PER_BLOCK, secondBlockBuffer);
  96.     indexInfoPtr->blockAddrPtr = 
  97.     (int *) (secondBlockBuffer + sizeof(int) * indexInfoPtr->secondIndex);
  98.  
  99.     return(SUCCESS);
  100. }
  101.  
  102.  
  103. /*
  104.  *----------------------------------------------------------------------
  105.  *
  106.  * FsGetFirstIndex --
  107.  *
  108.  *    Initialize the index structure.  This will set up the index info
  109.  *    structure so that it contains a pointer to the desired block pointer.
  110.  *
  111.  * Results:
  112.  *    A status indicating whether there was sufficient space to allocate
  113.  *    indirect blocks.
  114.  *
  115.  * Side effects:
  116.  *    The index structure is initialized.
  117.  *
  118.  *----------------------------------------------------------------------
  119.  */
  120.  
  121. ReturnStatus
  122. FsGetFirstIndex(handlePtr, blockNum, indexInfoPtr)
  123.     register Fsio_FileIOHandle        *handlePtr;    /* Handle for file that are 
  124.                           indexing. */
  125.     register int        blockNum;      /* Where to start indexing. */
  126.     register BlockIndexInfo *indexInfoPtr; /* Index structure to initialize.*/
  127. {
  128.     register Fsdm_FileDescriptor *descPtr;
  129.     register int          indirectBlock;
  130.  
  131.     descPtr = handlePtr->descPtr;
  132.     indexInfoPtr->firstBlockNil = TRUE;
  133.     indexInfoPtr->blockNum = blockNum;
  134.  
  135.     if (blockNum < FSDM_NUM_DIRECT_BLOCKS) {
  136.     /*
  137.      * This is a direct block.
  138.      */
  139.     indexInfoPtr->indexType = FS_DIRECT;
  140.     indexInfoPtr->blockAddrPtr = &descPtr->direct[blockNum];
  141.     return(SUCCESS);
  142.     }
  143.  
  144.     /*
  145.      * Is an indirect block.
  146.      */
  147.  
  148.     blockNum -= FSDM_NUM_DIRECT_BLOCKS;
  149.     indirectBlock = blockNum / FSDM_INDICES_PER_BLOCK;
  150.     if (indirectBlock == 0) {
  151.     /*
  152.      * This is a singly indirect block.
  153.      */
  154.     indexInfoPtr->indexType = FS_INDIRECT;
  155.     indexInfoPtr->firstIndex = blockNum;
  156.     } else {
  157.     /*
  158.      * This a doubly indirect block.
  159.      */
  160.     indexInfoPtr->indexType = FS_DBL_INDIRECT;
  161.     indexInfoPtr->firstIndex = indirectBlock - 1;
  162.     indexInfoPtr->secondIndex = blockNum -
  163.                     indirectBlock * FSDM_INDICES_PER_BLOCK;
  164.     }
  165.  
  166.     /*
  167.      * Finish off by making the block pointer accessible.  This may include
  168.      * reading indirect blocks into the cache.
  169.      */
  170.  
  171.     return(MakePtrAccessible(handlePtr, indexInfoPtr, descPtr));
  172. }
  173.  
  174.  
  175. /*
  176.  *----------------------------------------------------------------------
  177.  *
  178.  * FsGetNextIndex --
  179.  *
  180.  *    Put the correct pointers in the index structure to access the
  181.  *    block after the current block.
  182.  *
  183.  * Results:
  184.  *    A status indicating whether there was sufficient space to allocate
  185.  *    indirect blocks if they were needed.
  186.  *
  187.  * Side effects:
  188.  *    The allocation structure is modified.
  189.  *
  190.  *----------------------------------------------------------------------
  191.  */
  192.  
  193. ReturnStatus
  194. FsGetNextIndex(handlePtr, indexInfoPtr)
  195.     register Fsio_FileIOHandle       *handlePtr;    /* Handle for file that is being
  196.                           indexed. */
  197.     register BlockIndexInfo *indexInfoPtr; /* Index structure to set up. */
  198. {
  199.     register Boolean          accessible = FALSE;
  200.     register Fsdm_FileDescriptor *descPtr;
  201.  
  202.     descPtr = handlePtr->descPtr;
  203.     indexInfoPtr->blockNum++;
  204.  
  205.     /*
  206.      * Determine whether we are now in direct, indirect or doubly indirect
  207.      * blocks.
  208.      */
  209.  
  210.     switch (indexInfoPtr->indexType) {
  211.     case FS_DIRECT:
  212.         if (indexInfoPtr->blockNum < FSDM_NUM_DIRECT_BLOCKS) {
  213.         /*
  214.          * Still in the direct blocks.
  215.          */
  216.         indexInfoPtr->blockAddrPtr++;
  217.         accessible = TRUE;
  218.         } else {
  219.         /*
  220.          * Moved into indirect blocks.
  221.          */
  222.         indexInfoPtr->indexType = FS_INDIRECT;
  223.         indexInfoPtr->firstIndex = 0;
  224.         }
  225.         break;
  226.     case FS_INDIRECT:
  227.         if (indexInfoPtr->blockNum < 
  228.             FSDM_NUM_DIRECT_BLOCKS + FSDM_INDICES_PER_BLOCK) {
  229.         /*
  230.          * Still in singly indirect blocks.
  231.          */
  232.         indexInfoPtr->blockAddrPtr++;
  233.         accessible = TRUE;
  234.         break;
  235.        } else {
  236.         /*
  237.          * Moved into doubly indirect blocks.
  238.          */
  239.         indexInfoPtr->firstIndex = 0;
  240.         indexInfoPtr->secondIndex = 0;
  241.         indexInfoPtr->indexType = FS_DBL_INDIRECT;
  242.         indexInfoPtr->firstBlockNil = TRUE;
  243.         }
  244.         break;
  245.     case FS_DBL_INDIRECT:
  246.         indexInfoPtr->secondIndex++;
  247.         if (indexInfoPtr->secondIndex == FSDM_INDICES_PER_BLOCK) {
  248.         indexInfoPtr->firstIndex++;
  249.         indexInfoPtr->secondIndex = 0;
  250.         } else {
  251.         indexInfoPtr->blockAddrPtr++;
  252.         accessible = TRUE;
  253.         }
  254.         break;
  255.     }
  256.  
  257.     /*
  258.      * Make the block pointers accessible if necessary.
  259.      */
  260.  
  261.     if (!accessible) {
  262.     return(MakePtrAccessible(handlePtr, indexInfoPtr, descPtr));
  263.     } else {
  264.     return(SUCCESS);
  265.     }
  266. }
  267. @
  268.